package logic

import (
	"3kz/zk3rpc/zk3rpc"
	"context"

	"3kz/api/internal/svc"
	"3kz/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List(req *types.ListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	List, err := l.svcCtx.Zk3Rpc.List(l.ctx, &zk3rpc.ListRequest{
		Page:        int64(req.Page),
		Size:        int64(req.Size),
		ProductName: req.ProductName,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "展示成功",
		Code:    "200",
		Data:    List,
	}, nil

}
